package com.study.myTest;

import org.junit.Test;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;

/**
 * @program: java8
 * @description: stream 测试
 * @author: yangyb
 * @create: 2021-11-24 19:40
 **/
public class StreamTest {
    @Test
    public void testStream() {


        List<Integer> list = Arrays.asList(1, 2, 3, 4);

        List<BigDecimal> arrayList = new ArrayList<>();
        BigDecimal bigDecimal1 = BigDecimal.valueOf(120000.0000);

        int sum = list.stream().mapToInt(e -> e).sum();
        int intValue = list.stream().reduce(0, (intOne, intTwo) -> intOne + intTwo);
        Integer reduce = list.stream().reduce(0, Integer::sum);

        System.out.println(sum);
        System.out.println(intValue);
        System.out.println(reduce);

    }

    @Test
    public void testStream2() {
        int reduce = IntStream.of(new int[]{1, 2, 3, 4}).reduce(0, Integer::sum);
        //[1,4)
        IntStream.range(1, 4).forEach(System.out::println);
        //[1,3]
        IntStream.rangeClosed(1, 3).forEach(System.out::println);
        System.out.println(reduce);


    }
}
